#include <bits/stdc++.h>

using namespace std;

struct node
{
    int index;
    int numofspace;
};

string tmp;
node a[10001];
int father[10001],have[10001];

void showpath(int num){
    std::vector<int> v;
    while(num!=0){
        v.emplace_back(num);
        num=father[num];
    }
    printf("0000");
    for(int i=v.size()-1;i>=0;--i){
        printf("->%04d", v[i]);
    }
    printf("\n");
}

int main(int argc, char const *argv[])
{
    int n;scanf("%d%*c",&n);
    for (int i = 0; i < n; ++i)
    {
        getline(cin,tmp,'\n');
        int numofspace=0;
        while(tmp[numofspace]==' ')++numofspace;
        a[i].numofspace=numofspace;
        stringstream ss(tmp);
        int index;ss>>index;
        a[i].index=index;
        have[index]=1;
        for (int j = i-1; j >=0 ; --j)
        {
            if(a[j].numofspace<a[i].numofspace){
                father[index]=a[j].index;
                break;
            }
        }
    }

    int k;scanf("%d",&k);
    for (int i = 0; i < k; ++i)
    {
        int num;scanf("%d",&num);
        if(have[num]==1)showpath(num);
        else printf("Error: %04d is not found.\n",num);
    }
    return 0;
}